﻿
<template>
    <div>
        <!-- 添加按钮 -->
        <div class="btn-add">
            <button type="button" class="btn btn-info btn-lg" @click="Add()"><i class="iconfont icon-jiahao ft12 mr5"></i>新建应用</button>

            <button type="button" class="btn btn-success btn-lg" @click="Dryy()"><i class="iconfont icon-jiahao ft12 mr5"></i>导入应用</button>
        </div>
        <!-- 按条件选择 -->
        <div class="tab-filter-type">
            <div class="oh mt20">
                <h5 class="pull-left tr">全部类型：</h5>
                <ul class="tab-type ft14">
                    <li><span class="active">全部</span></li>
                    <!--<li><span>SQLSERVER</span></li>
                <li><span>MYSQL</span></li>-->
                </ul>
            </div>
        </div>
        <!-- 表格 -->
        <div class="default-tab ft14 padding20 hover-btn">

            <base-table :pzoption="tableop">
            </base-table>



        </div>

        <div class="modal fade" id="DSModal" role="dialog">
            <div class="modal-dialog" role="document" style="width: 600px">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title">自定义应用</h4>
                    </div>
                    <div class="modal-body">
                        <div class="form-horizontal">
                            <div class="form-group">
                                <label class="col-xs-3 control-label text-right">父应用名称</label>
                                <div class="col-xs-7">
                                    <input type="text" class="form-control" v-model="SelDSourceItem.ModelType" placeholder="父应用名称" />
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="branchName" class="col-xs-3 control-label text-right">父应用代码</label>
                                <div class="col-xs-7">
                                    <input type="text" class="form-control" v-model="SelDSourceItem.PModelCode" placeholder="父应用代码" />
                                </div>
                            </div>


                            <div class="form-group">
                                <label class="col-xs-3 control-label text-right">应用名称</label>
                                <div class="col-xs-7">
                                    <input type="text" class="form-control" v-model="SelDSourceItem.ModelName" placeholder="应用名称" />
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-xs-3 control-label text-right">应用代码</label>
                                <div class="col-xs-7">
                                    <input type="text" class="form-control" v-model="SelDSourceItem.ModelCode" placeholder="应用代码" />
                                </div>
                            </div>

                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button type="button" class="btn btn-success" id="conaddForder" @click="ConfirmData()">确&nbsp;&nbsp;认</button>
                    </div>
                </div>
            </div>
        </div>

        <div class="modal fade" id="DRModal" role="dialog">
            <div class="modal-dialog" role="document" style="width: 600px">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title">导入应用</h4>
                    </div>
                    <div class="modal-body">
                        <div class="form-horizontal">
                            <div class="form-group">
                                <label class="col-xs-5 control-label text-right">上传应用json脚本</label>
                                <div class="col-xs-5">
                                    <input type="file" id="files"  @change="changefile();">
                                </div>
                            </div>
                          
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button type="button" class="btn btn-success" id="conaddForder" @click="ConfirmDR()">确&nbsp;&nbsp;认</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
    module.exports = {
        props: ['pdata'],
        components: {
            'base-table': httpVueLoader('/ViewV5/Base/Vue/Table.vue')
        },
        data: function () {
            return {
                VIEWS: [],
                SelDSourceItem: {},
                tableop: {
                    title: "自定义应用",
                    issel: true,
                    iscz: true,
                    dataset: [],
                    dtcxdata: [{ cxname: "父应用名称", cxzd: "ModelType", cxdata: "", cal: "0", datatype: "1", dtsource: [], val: "" }],
                    czltabledata: [
                        {
                            colname: "应用管理", bttype: "text", isshow: true,  mangefun: function (rowdata) {
                                window.open("/ViewV5/AppPage/XTGL/YYEDIT.html?ID=" + rowdata.ID, "_blank");
                            },
                        },
                        {
                            colname: "删除", bttype: "text", isshow: true,  mangefun: function (rowdata) {
                                this.$parent.DelDSource(rowdata);
                            }
                        }
                    ],
                    collist: [
                        { colid: "ModelType", colname: "父应用名称", isshow: true, istip: true },
                        { colid: "PModelCode", colname: "父应用代码", isshow: true, istip: true },
                        { colid: "ModelName", colname: "应用名称", isshow: true, istip: true },
                        { colid: "ModelCode", colname: "应用代码", isshow: true, istip: true },
                        { colid: "CRUser", colname: "创建人", isshow: false, istip: true },
                        { colid: "CRDate", colname: "创建时间", isshow: false, istip: true },

                    ]
                }
            }
        },
        methods: {
            Dryy: function () {
                $('#DRModal').modal('show');
            },
            ConfirmDR: function () {
                var pro = this;
                var selectedFile = document.getElementById('files').files[0];
                //var name = selectedFile.name;//读取选中文件的文件名
                //var size = selectedFile.size;//读取选中文件的大小
                var reader = new FileReader();//这是核心,读取操作就是由它完成.
                reader.readAsText(selectedFile);//读取文件的内容,也可以读取文件的URL
                reader.onload = function () {
                    //当读取完成后回调这个函数,然后此时文件的内容存储到了result中,直接操作即可
                    var yydata = this.result;
                    $.getJSON("/api/Auth/ExeAction?Action=DRYYJB", { P1: yydata }, function (result) {
                        if (!result.ErrorMsg) {
                            top.ComFunJS.winsuccess("操作成功");
                            $('#DRModal').modal('hide');
                            pro.InitWigetData();
                        }
                    });
                }

             
            },
            changefile: function () {
                var selectedFile = document.getElementById('files').files[0];
                var name = selectedFile.name;//读取选中文件的文件名
                var size = selectedFile.size;//读取选中文件的大小
                var reader = new FileReader();//这是核心,读取操作就是由它完成.
                reader.readAsText(selectedFile);//读取文件的内容,也可以读取文件的URL
                reader.onload = function () {
                    //当读取完成后回调这个函数,然后此时文件的内容存储到了result中,直接操作即可
                    console.log(this.result);
                }
            },
            Add: function () {
                var pro = this;
                pro.SelDSourceItem = { PModelCode: "WORK", ModelType: "工作台", ModelName: "", ModelCode: "", IsSys: "0", ORDERID: "0", ID: "0" };
                $('#DSModal').modal('show');
            },
            edit: function (item) {
                var pro = this;
                pro.SelDSourceItem = {};
                pro.SelDSourceItem = item;
                $('#DSModal').modal('show');
            },
            ConfirmData: function () {
                var pro = this;
                $.getJSON('/api/Auth/ExeAction?Action=ADDYY', { P1: JSON.stringify(pro.SelDSourceItem) }, function (resultData) {
                    if (resultData.ErrorMsg == "") {
                        top.ComFunJS.winsuccess("操作成功");
                        $('#DSModal').modal('hide');
                        pro.InitWigetData();
                    }
                })
            },
            DelDSource: function (item) {
                var pro = this;
                ComFunJS.winconfirm("删除应用的同时会删除应用下的菜单,确认要删除吗", function () {
                    $.getJSON('/api/Auth/ExeAction?Action=DELYY', { "P1": item.ID }, function (result) {
                        if (result.ErrorMsg == "") {
                            ComFunJS.winsuccess("删除成功");
                            pro.InitWigetData();
                        }
                    })
                }, function () { })
            },
            InitWigetData: function () {
                var pro = this;
                $.getJSON('/api/Auth/ExeAction?Action=GETYYDATA', { P2: "0" }, function (resultData) {
                    if (resultData.Result.length > 0) {
                        pro.tableop.dataset = resultData.Result;
                    }
                })
              
            },
        },
        mounted: function () {
            var pro = this;
            pro.$nextTick(function () {
                pro.InitWigetData();
            })

        },
        watch: {

        }
    };
</script>